class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int prev = 0, cur = 1;
        int ret = 0;
        while (cur < timeSeries.size())
        {
            if (timeSeries[cur] - timeSeries[prev] < duration)
                ret += (timeSeries[cur] - timeSeries[prev]);
            else
                ret += duration;
            prev++;
            cur++;
        }
        ret += duration;
        return ret;
    }
};